package br.edu.ufcg.splab.util.commands;

import org.naturalcli.IParameterType;

public class PositiveIntegerParameter implements IParameterType {
	
	/**
	 * {@inheritDoc}
	 */
	public String validationMessage(String value) {
		return this.validateParameter(value) ? null : value + " is not a positive integer.";
	}
	
	/**
	 * {@inheritDoc}
	 */
	public boolean validateParameter(String value) {
		try{
			int intRepresentation = Integer.valueOf(value);
			return (intRepresentation >= 0 ? true : false);
		}catch(NumberFormatException e){
			return false;
		}
	}
	
	/**
	 * {@inheritDoc}
	 */
	public String getParameterTypeName() {
		return "positiveinteger";
	}
	
	/**
	 * {@inheritDoc}
	 */
	public Object convertParameterValue(String value) {
		return Integer.valueOf(value);
	}

}
